package com.teach.javafxclient.controller.base;

import com.teach.javafxclient.Globalvar;
import com.teach.javafxclient.util.HttpUtil;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.*;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Liang Jianlin
 * @date 2024-05-30 20:30
 */
public class PostHonorController {
    public ComboBox studentCombobox;
    public ComboBox typeComboBox;
    public TextField name;
    public TextArea description;
    public Label output;
    public Button confirm;
    Map<String,Long> studentMap = new HashMap<>();
    public void initialize(){
        HttpResponse<JsonNode> response = HttpUtil.get(Globalvar.baseUrl+"/api/students")
                .header("Accept", "application/json")
                .asJson();
        JsonNode responseBody = response.getBody();
        JSONArray jsonArray1 = responseBody.getArray();
        for (int i = 0; i < jsonArray1.length(); i++) {
            JSONObject jsonObject1 = jsonArray1.getJSONObject(i);
            String name= jsonObject1.getString("name");
            Long studentId= Long.valueOf(jsonObject1.getString("studentId"));
            studentCombobox.getItems().add(name+studentId);
            studentMap.put(name+studentId, studentId);
        }
        ObservableList<String> items= FXCollections.observableArrayList("院级","校级","省级","国家级");
        typeComboBox.setItems(items);
    }
}
